/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUILayer;
import javax.swing.table.*;
import java.util.ArrayList;
import ModelLayer.*;


public class TableModelOrder extends DefaultTableModel {
    
    private ArrayList<PartOrder> data;
    private String textfield;

    public TableModelOrder()
    {
        data = new ArrayList<PartOrder>();
    }

    @Override
    public boolean isCellEditable(int row, int column) {
        return false;
    }
    
    public void setData(ArrayList<PartOrder> data)
    {
        this.data = data;
        fireTableDataChanged();
    }

    public ArrayList<PartOrder> getData() {
        return data;
    }
    
    @Override
    public int getColumnCount() {
        return 9;
    }

    @Override
    public int getRowCount() 
    {
        if(data == null)
        {
            return 0;
        }
        else
        {
            return data.size();
        }
    }

    @Override
    public String getColumnName(int column) {
        String columnName = "";
        switch(column)
        {
            case 0:
            columnName = "Type";
            break;  
            case 1:
            columnName = "Navn";
            break;   
            case 2:
            columnName = "Timer";
            break; 
            case 3:
            columnName = "Antal";
            break; 
            case 4:
            columnName = "Dybde";
            break;
            case 5:
            columnName = "Netto";
            break;
            case 6:
            columnName = "Brutto";
            break;
            case 7:
            columnName = "Difference";
            break;
            case 8:
            columnName = "Faktisk tid/antal";
            break;
        }        
        return columnName;
    }
    
    @Override
    public Object getValueAt(int row, int column) 
    {
        Object value = null;  
        
        String type = "";
        String fName = "";
        double hours = 0;
        double amount = 0;
        String depth = "";
        double netto = 0;
        double brutto = 0;
        double difference = 0;
        double actual = 0;
        
        if(data.get(row).getEmployee() != null)
        {
            type = "Medarbejder";
            fName = data.get(row).getEmployee().getfName();
            hours = data.get(row).getAmount();
            netto = data.get(row).getAmount() * data.get(row).getEmployee().getInternalHourlyWage();
            brutto = data.get(row).getAmount() * data.get(row).getEmployee().getExternalHourlyWage();
            difference = brutto - netto;
        }
        if(data.get(row).getMachine() != null)
        {
            type = "Maskine";
            fName = data.get(row).getMachine().getName();
            hours = data.get(row).getAmount();
        }
        if(data.get(row).getProDesc() != null)
        {
            type = "Produkt";
            fName = data.get(row).getProDesc().getName();
            amount = data.get(row).getAmount();
            netto = data.get(row).getAmount() * data.get(row).getProDesc().getPurchasePrice();
            brutto = data.get(row).getAmount() * data.get(row).getProDesc().getSalesPrice();
            difference = brutto - netto;
        }
           
            switch(column)
        {
            case 0:
                value = type;
                break;
            case 1:
                value = fName;
                break;
            case 2:
                value = hours;
                break;
            case 3:
                value = amount;
                break; 
            case 4:
                value = depth;
                break;
            case 5:
                value = netto;
                break;
            case 6:
                value = brutto;
                break;
            case 7:
                value = difference;
                break;
            case 8:
                value = actual;
                break;
        }     
        return value;
    }    
    
    public void setText(String text)
    {
        textfield = text;
    }      
}
